package com.lichao.argorithm.impl.linked;

import com.lichao.argorithm.api.Stack;

public class LinkedStack<T> implements Stack<T>{
	private Node first;
	private int N;
	
	private class Node{
		T item;
		Node next;
	}

	@Override
	public void push(T t) {
		Node oldFirst = first;
		first = new Node();
		first.item = t;
		first.next = oldFirst;
		N++;
	}

	@Override
	public T pop() {
		T t = first.item;
		first = first.next;
		N--;
		return t;
	}

	@Override
	public boolean isEmpty() {
		return N == 0;
	}

	@Override
	public int size() {
		return N;
	}

}
